package com.xiaouyudeguang.common.exception;

import com.xiaouyudeguang.common.collect.MapBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.oauth2.common.exceptions.InvalidTokenException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Slf4j
@ResponseBody
@ControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class OAuth2ExceptionController {

    /**
     * s
     * 用于处理异常的
     *
     * @return
     */
    @ExceptionHandler(InvalidTokenException.class)
    public Map<?, ?> exception(InvalidTokenException e) {
        log.error(e.getMessage(), e);
        return MapBuilder.builder().put("error", "invalid_token").put("error_description", e.getMessage()).build();
    }

}